<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.book.DbManager"%>
<%@page import="java.sql.ResultSet"%>
<html>
<head>
<link type="text/css" rel="stylesheet" href="book.css">
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
<script type="text/javascript">
	function sf() {
		var isbn = document.getElementById("isbn").value;
		if (isbn == "" || isbn == null) {
			alert('isbn 不能为空,只能是标准书号！');
			return false;
		}
		alert(isbn + '符合标准!确定添加!');
		document.forms[0].submit();
	}
</script>
</head>
<body>
<div>
<h3 align="center">输入图书相关信息</h3>
</div>
<form action="insert.jsp" method="post">
<%
	String isbn = request.getParameter("isbn");
	boolean isNew = (isbn == null);
	if (isNew) {
%>
<table align="center" width="380" height="400" bgcolor="#606060">
	<tr align="center">
		<td>isbn:</td>
		<td><input name="isbn" type="text" id="isbn"></td>
	</tr>
	<tr align="center">
		<td>name:</td>
		<td><input name="name" type="text"></td>
	</tr>
	<tr align="center">
		<td>author:</td>
		<td><input name="author" type="text"></td>
	</tr>
	<tr align="center">
		<td>price:</td>
		<td><input name="price" type="text"></td>
	</tr>
	<tr align="center">
		<td><input type="button" value="添   加" onclick=
	sf();
></td>
		<td><input type="button" value="取   消"></td>
	</tr>
</table>
</form>
<%
	}
%>
<%
	String name = request.getParameter("name");
	String author = request.getParameter("author");
	String price = request.getParameter("price");

	if (null != isbn) {
		String insertsql = "insert into book(isbn,name,author,price)values('"
				+ isbn
				+ "','"
				+ name
				+ "','"
				+ author
				+ "',"
				+ price
				+ ")";
		DbManager.exeSql(insertsql);
		String selectSql = "select * from book where isbn='" + isbn
				+ "'";

		try {
			ResultSet rst = DbManager.getRst(selectSql);
%>
<table align="center">
	<tr>
		<td>
		<h1>
		<%
			out.println(" insert success !");
		%>
		</h1>
		</td>
	</tr>
</table>
<%
	} catch (RuntimeException e) {
			out.println(" insert fail !");
			e.printStackTrace();
		}
	}
%>
<table align="center">
	<tr>
		<td>
		<h3><a
			href="http://localhost:8080/struts2-blank-2.0.14/example/adminBook.jsp">返回管理页面</a></h3>
		</td>
	</tr>
</table>
</body>
</html>